<title>BoxBilling Install Manager</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<div id="header">
<h3>BoxBilling安装管理器</h3>
<a href="http://x-lu.com">By x-lu.com</a>
<br>
<?php
$a = isset($_GET['a'])?$_GET['a']:'none';
$mmc = memcache_init();
$test = memcache_get($mmc,"log.log");
switch ($a) {
	case 'del':
		unistall();
		break;
	case 'log':
		downloadLog();
		break;
	case 'rebuild':
		rebuildBox();
		break;
	default:
		index();
		break;
}
function rebuildBox()
{
	file_put_contents("saemc://log.log", "test\n");
	echo 'Rebuild finished<br>';
	
}
function index()
{
	global $mmc;
	global $test;
if($test){
	echo 'BoxBilling installed! Click <a href="'.$_SERVER['PHP_SELF'].'?a=del" >Uninstall</a> to Uninstall it';
	echo '<br>Log file exists,Click  <a href="'.$_SERVER['PHP_SELF'].'?a=log" >DownLoad</a> to DownLoad it';
	}
else
	echo 'BoxBilling 还未安装 点击 <a href="/install" >这里</a> 安装';
	echo '如果memcache缓存丢失导致安装信息丢失，点击这里 <a href="?a=rebuild" >重建安装信息</a> ';
}
function downloadLog()
{
	global $mmc;
	global $test;
	echo $test;
}
function unistall()
{
	unlink('saemc://log.log');
	echo 'Uninstasll saemc finished<br>';
	$hostname =SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT;
	$userid = SAE_MYSQL_USER;
	$password = SAE_MYSQL_PASS;
	$dbname = SAE_MYSQL_DB;
	$connect = MySQL_connect($hostname,$userid,$password);
	mysql_select_db($dbname);
	$result = mysql_query("show table status from $dbname",$connect);
	while($data=mysql_fetch_array($result)) {
	mysql_query("drop table $data[Name]");
	}
	echo 'Uninstasll MySQL finished';
}
